package com.takerfan.soundboard;

import java.io.File;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class SoundBoardList extends ListActivity {
	private static String rawpath = "/sdcard/SoundBoards";
	
	private static Context defContext;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    defContext = this;
	    
	    File[] fileArray = new File(rawpath).listFiles();
	    String[] arFolders = new String[fileArray.length];

	    for (int i = 0; i < fileArray.length; i++) {
	        if (fileArray[i].isDirectory()) {
	        	arFolders[i] =  fileArray[i].getName();
	        }
	      }

	    setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arFolders));
	    getListView().setTextFilterEnabled(true);
	    getListView().setOnItemClickListener(listener);
	}
	
	 AdapterView.OnItemClickListener listener=new AdapterView.OnItemClickListener() {
		 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
			 TextView v = (TextView) view;
			 Intent intent = new Intent(defContext, SoundBoard.class);
			 intent.putExtra("folder", v.getText());
			 intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
			 intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
			 startActivity(intent);
		 }
	 };
}
